# coding:utf-8
import numpy as np
from sklearn import neighbors
import pandas as pd
import pickle

data = pd.read_table("orders.tbl", sep='|')
data.sort_values('o_totalprice', inplace=True)
data.reset_index(drop=True, inplace=True)
print(data.index)
sample = data.sample(frac=0.1)

row_index = np.array(sample.index.tolist())
# X = row_index[:, np.newaxis]
print(sample.index)
o_totalprice = np.array(sample['o_totalprice'])
# Y = o_totalprice[:, np.newaxis]


reg = neighbors.KNeighborsRegressor()

reg.fit(row_index.reshape(-1, 1), o_totalprice)

# reg = qreg.QReg(base_models=["linear", "polynomial"], verbose=False).fit(row_index.reshape(-1, 1),o_totalprice)
print(reg.predict([[0]]))
output = open('reg.pkl', 'wb')
pickle.dump(reg, output)
output.close()
